package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.vo.SkuInfoVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("admin/product")
@RestController
public class SkuController {

    @Autowired
    SkuInfoService skuInfoService;

    @GetMapping("/list/{pn}/{ps}")
    public Result list(@PathVariable("pn") Long pn,
                       @PathVariable("ps") Long ps){
        Page<SkuInfo> skuInfos = new Page<>(pn,ps);

        Page<SkuInfo> result = skuInfoService.page(skuInfos);

        return Result.ok(result);

    }

    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfoVo vo){
        skuInfoService.saveSkuInfo(vo);
        return Result.ok();
    }

}
